<?php

namespace App\Http\Controllers\Api\Admin;

use App\Http\Controllers\Api\Controller;
use App\Http\Requests\Api\BannerRequest;
use App\Models\Banner;
use App\Transformers\BannerTransformer;
use Illuminate\Http\Request;

class BannerController extends Controller
{
    //添加轮播图
    public function store(BannerRequest $request, Banner $item){

        $item->img_url = $request->img_url;
        $item->url = $request->url;
        $item->sort = $request->sort;
        $item->save();

        return $this->response->item($item,new BannerTransformer());
    }

    public function destory(Banner $banner){

        $banner->delete();
        return $this->response->array(['message'=>'删除成功'])->setStatusCode(204);
    }

    public function update(BannerRequest $request, Banner $banner){
        $banner->update([
            $banner->img_url =$request->img_url,
            $banner->url = $request->url,
            $banner->sort = $request->sort,
        ]);
        return $this->response->array(['message'=>'修改成功'])->setStatusCode(200);
    }

    public function list(Banner $banner){
        $result=$banner->get();
        return $this->response->array($result);
    }
}
